package org.senseframework.support.example.hibernate.controller;

import org.senseframework.support.core.utils.JSONUtils;
import org.senseframework.support.example.hibernate.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by emeey on 2016/11/20.
 */
@Controller
@RequestMapping("/hibernate/user")
public class HibernateUserController {

    @ResponseBody
    @RequestMapping(value = {"/register"})
    public Object register(User user) {
        user.saveOrUpdate();
        return "user save success!";
    }

    @ResponseBody
    @RequestMapping(value = {"/update"})
    public Object update(User user) {
        user.saveOrUpdate();
        return "user save success!";
    }

    @ResponseBody
    @RequestMapping(value = {"/list"})
    public Object list() {
        List list = User.build(User.class).limit(false).list();
        return JSONUtils.toJSONString(list);
    }
}
